package top.ochiamalu.aioj.controller;

import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ochiamalu.aioj.common.BaseResponse;
import top.ochiamalu.aioj.common.ErrorCode;
import top.ochiamalu.aioj.domain.dto.thumb.ThumbDTO;
import top.ochiamalu.aioj.enums.ThumbTypeEnum;
import top.ochiamalu.aioj.exception.BusinessException;
import top.ochiamalu.aioj.service.ThumbService;
import top.ochiamalu.aioj.util.ResultUtils;

import javax.annotation.Resource;

/**
 * 点赞控制器
 *
 * @author ochiamalu
 * @date 2025/03/07
 */
@RestController
@RequestMapping("/thumbs")
public class ThumbController {

    @Resource
    private ThumbService thumbService;

    /**
     * 点赞题目
     *
     * @param thumbDTO 点赞DTO
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @PostMapping("/question")
    public BaseResponse<Boolean> thumbQuestion(@RequestBody ThumbDTO thumbDTO) {
        if (thumbDTO.getQuestionId() == null || thumbDTO.getQuestionId() <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数错误");
        }
        StpUtil.checkLogin();
        return ResultUtils.success(thumbService.thumb(thumbDTO.getQuestionId(), ThumbTypeEnum.QUESTION));
    }

    /**
     * 点赞题集
     *
     * @param thumbDTO 点赞DTO
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @PostMapping("/set")
    public BaseResponse<Boolean> thumbSet(@RequestBody ThumbDTO thumbDTO) {
        if (thumbDTO.getSetId() == null || thumbDTO.getSetId() <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数错误");
        }
        StpUtil.checkLogin();
        return ResultUtils.success(thumbService.thumb(thumbDTO.getSetId(), ThumbTypeEnum.SET));
    }
}
